//
//  WclKeyBoardView.m
//  YZMicroStock
//
//  Created by apple on 2017/11/23.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "WclKeyBoardView.h"

@interface WclKeyBoardView ()

@property (weak, nonatomic) IBOutlet UIView *viewFirst;

@property (weak, nonatomic) IBOutlet UIView *viewSecond;

@property (weak, nonatomic) IBOutlet UIView *viewThree;


@end

@implementation WclKeyBoardView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)awakeFromNib{
    [super awakeFromNib];
     [YZMAppStyle addTopLineViewWithParentView:self.viewFirst color:[YZMAppStyle colorForLine]];
    [YZMAppStyle addLineViewWithParentView:self.viewFirst color:[YZMAppStyle colorForLine]];
    [YZMAppStyle addLineViewWithParentView:self.viewSecond color:[YZMAppStyle colorForLine]];
    UIButton *btn = [self viewWithTag:114];
    [YZMAppStyle addTopLineViewWithParentView:btn color:[YZMAppStyle colorForLine]];
    for (NSInteger i = 100; i < 116; i++) {
        UIButton *button = [self viewWithTag:i];
        [button addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventTouchUpInside];
        if (i < 104) {
            [button setBackgroundImage:[self btnNumGroundImage] forState:UIControlStateNormal];
            [button setBackgroundImage:[self btnGroundImage] forState:UIControlStateHighlighted];
        }else{
            if (i == 113 || i == 115) {
                [button setBackgroundImage:[self btnGroundImage] forState:UIControlStateHighlighted];
            }else{
                [button setBackgroundImage:[self btnNumGroundImage] forState:UIControlStateHighlighted];
            }
        }
        
    }
    
}

- (UIImage *)btnGroundImage
{
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 258 / 4.0), NO, [UIScreen mainScreen].scale);
    [[YZMAppStyle colorForWhite] setFill];
    CGContextFillRect(UIGraphicsGetCurrentContext(),  CGRectMake(0, 0, 100, 258 / 4.0));
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (UIImage *)btnNumGroundImage
{
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 258 / 4.0), NO, [UIScreen mainScreen].scale);
    [[YZMAppStyle colorForHighted] setFill];
    CGContextFillRect(UIGraphicsGetCurrentContext(),  CGRectMake(0, 0, 100, 258 / 4.0));
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (void)changeText:(UIButton *)btn{
    if (btn.tag == 115) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(deleteString)]) {
            [self.delegate deleteString];
        }
        return;
    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeString:)]) {
        [self.delegate changeString:btn.currentTitle];
    }
    
}



@end
